//
//  MTNativeBaseViewController.m
//  ebook
//
//  Created by mt on 17/1/21.
//  Copyright © 2017年 Moton. All rights reserved.
//

#import "MTNativeBaseViewController.h"
#import "MBProgressHUD.h"

@interface MTNativeBaseViewController ()

@property (nonatomic, strong) MBProgressHUD *hud;
@property (nonatomic, retain) UIView *coverView;//失败界面

@end

@implementation MTNativeBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//加载框
-(MBProgressHUD *)hud{
    if (!_hud) {
        _hud = [[MBProgressHUD alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
        _hud.labelText = kInfoLocalLoad;
    }
    return _hud;
}

- (void)showHud {

    [self.view addSubview:self.hud];
    [self.view bringSubviewToFront:self.hud];
    [self.hud show:YES];
}

- (void)hideHud {
 
    [self.hud removeFromSuperview];
    self.hud = nil;
}

//失败界面
-(UIView *)coverView {
    
    if (!_coverView) {
        
        _coverView = [[UIView alloc] init];
        _coverView.frame = CGRectMake(0, 0, MTScreenW, MTScreenH-SafeAreaTopHeight);
        _coverView.backgroundColor = MTConfigColor(@"MTBookCity_CoverViewBg_Color");//使用图片一样的背景色
        
        UIImage *image = [UIImage imageNamed:@"loadFail"];
        UIImageView *icon = [[UIImageView alloc] init];
        icon.frame = CGRectMake((MTScreenW-208)/2, 40, 208, 256);
        icon.image = image;
        icon.userInteractionEnabled = YES;
        [_coverView addSubview:icon];
        
        UILabel *titleLabel = [[UILabel alloc] init];
        titleLabel.frame = CGRectMake(0, CGRectGetMaxY(icon.frame), MTScreenW, 80);
        titleLabel.textAlignment = NSTextAlignmentCenter;
        titleLabel.text = @"连接失败，请检查网络连接\n点击屏幕重试";
        titleLabel.numberOfLines = 2;
        
        titleLabel.font = [UIFont systemFontOfSize:16.0];
        titleLabel.textColor = MTConfigColor(@"MTBookCity_titleLabelText_Color");
        [_coverView addSubview:titleLabel];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(reloadView)];
        [self.view addGestureRecognizer:tap];
    }
    
    return _coverView;
}

- (void)showFailedView {
    
    [self.view addSubview:self.coverView];
    [self.view bringSubviewToFront:self.coverView];
}

- (void)hideFailedView {
    
    [self.coverView removeFromSuperview];
    self.coverView = nil;
}

- (void)reloadView {}

@end
